<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<table cellpadding="0" cellspacing="0" width="100%" style="font-size:10px;font-weight:normal;border:1px solid gray;">
    <tr>
        <td width="50%" align="center">Componente</td>
        <td width="20%" align="center">Sala</td>
        <td width="30%" align="center">Período</td>
    </tr>
    <sql:query var="queryComp" dataSource="jdbc/dbo_MicrosoftSQLServer">
        select distinct id_reserva, g.ordem, c.id_componente,g.id_sala,
        desc_componente,
        codigo_componente,
        carga_componente,
        data_inicio,
        data_fim,
        subturma
        from Componentes c
        inner join reservas g on g.id_componente=c.id_componente
        where g.id_modulo=?
        and g.id_turma=?
        order by ordem
        <sql:param value="${param.id_modulo}"/>
        <sql:param value="${param.id_turma}"/>
    </sql:query>
    <sql:query var="querySala" dataSource="jdbc/dbo_MicrosoftSQLServer">
        select * from salas
        inner join unidades on salas.id_unidade=unidades.id_unidade
        order by desc_unidade,desc_sala
    </sql:query>
    <c:choose>
        <c:when test="${!empty queryComp.rows}">
            <c:forEach var="comp" items="${queryComp.rows}">
                <tr>
                    <td>
                        <input type="hidden" value="${comp.id_componente}" id="id_componente" name="id_componente">
                        <input type="hidden" value="${comp.id_reserva}" id="id_reserva" name="id_reserva" >
                        <input type="radio" value="${comp.id_componente}" id="id_componente_salas" name="id_componente_salas" onclick="reloadGrid($(this).val())">
                        <input type="text" value="${comp.ordem}" id="id_componente_ordem" name="ordem_${comp.id_reserva}" size="2">
                            ${fn:trim(comp.desc_componente)} - ${comp.carga_componente}h
                    </td>
                    <td><div id="sala">
                            <c:choose>
                                <c:when test="${!empty querySala.rows}">
                                    <select id="id_sala" name="id_sala_${comp.id_reserva}" >
                                        <option value="">Selecione uma sala</option>
                                        <c:forEach var="sala" items="${querySala.rows}">
                                            <option value="${sala.id_sala}" ${sala.id_sala==comp.id_sala?'selected':''}>${sala.desc_unidade} - ${sala.desc_sala}</option>
                                        </c:forEach>
                                    </select>
                                </c:when>
                                <c:otherwise>
                                    <p style="font-size: 12pt; color: red">Nenhuma sala foi encontrada.</p>
                                </c:otherwise>

                            </c:choose>
                        </div>
                    </td>
                    <fmt:formatDate var="data_inicio" value="${comp.data_Inicio}" pattern="dd/MM/yyyy"/>
                    <fmt:formatDate var="data_fim" value="${comp.data_fim}" pattern="dd/MM/yyyy"/>
                    <td>
                        <input type="text" id="data_inicio_${comp.id_reserva}" name="data_inicio_${comp.id_reserva}" size="8" value="${data_inicio}" maxlength="12" >
                        <input type="text" id="data_fim_${comp.id_reserva}" name="data_fim_${comp.id_reserva}" size="8" value="${data_fim}" >

                    </td>
                </tr>
            </c:forEach>
        </c:when>
        <c:otherwise>
            <p style="font-size: 12pt; color: red">Nenhum componente foi encontrado para o curso/módulo.</p>
        </c:otherwise>

    </c:choose>
</table>